package qjc.h_二叉树;

import com.二叉树.练习题.TreeNode;

public class h7_将有序数组转换为二叉搜索树 {
    /**
     * 递归遍历，二分
     *
     * @param nums
     * @return
     */
    public TreeNode sortedArrayToBST(int[] nums) {
        return helpTwo(nums, 0, nums.length - 1);
    }

    private TreeNode helpTwo(int[] nums, int left, int right) {
        int mid = (left + right) >>> 1;
        if (left > right) {
            return null;
        }
        TreeNode root = new TreeNode(nums[mid]);
        root.left = helpTwo(nums, left, mid - 1);
        root.right = helpTwo(nums, mid + 1, right);
        return root;
    }
}
